<?php
class BdApiController  extends CommonController
{
    /*
        添加店铺信息
    */
    public function addStoreInfo()
    {
        $storeId = $_POST['store_id'];
        $storeName = $_POST['store_name'];
        $startTime = $_POST['start_time'];
        $endTime = $_POST['end_time'];

        $BdApiModel = new  BdApiModel();

        $addStore = $BdApiModel->addStoreInfo($storeId, $storeName, $startTime, $endTime);

        if($addStore == false){
            $res = array(
                "errNo" => "0003"
            );
            $this->_response($res);
        }

        if(isset($addStore['errNo'])){
            $this->_response($addStore);
        }

        $res = array(
            "errNo" => "0",
            "data" => $addStore
        );
        
        $this->_response($res);
    }

    /*
        商户开业
    */
    public function openShop()
    {
        $store_id = $_POST['store_id'];

        $BdApiModel = new  BdApiModel();

        $openShop = $BdApiModel->openShop($store_id);

        if($openShop == false){
            $res = array(
                "errNo" => "0003"
            );
            $this->_response($res);
        }

        if(isset($openShop['errNo'])){
            $this->_response($openShop);
        }

        $res = array(
            "errNo" => "0",
            "data" => $openShop
        );
        
        $this->_response($res);
    }

    /*
        商户歇业
    */
    public function closeShop()
    {
        $store_id = $_POST['store_id'];

        $BdApiModel = new  BdApiModel();

        $closeShop = $BdApiModel->closeShop($store_id);
        
        if($closeShop == false){
            $res = array(
                "errNo" => "0003"
            );
            $this->_response($res);
        }

        if(isset($closeShop['errNo'])){
            $this->_response($closeShop);
        }

        $res = array(
            "errNo" => "0",
            "data" => $closeShop
        );
        
        $this->_response($res);
    }

    /*
        商户下线
    */
    public function offlineShop()
    {
        $store_id = $_POST['store_id'];

        $BdApiModel = new  BdApiModel();

        $offlineShop = $BdApiModel->offlineShop($store_id);
        
        if($offlineShop == false){
            $res = array(
                "errNo" => "0003"
            );
            $this->_response($res);
        }

        if(isset($offlineShop['errNo'])){
            $this->_response($offlineShop);
        }

        $res = array(
            "errNo" => "0",
            "data" => $offlineShop
        );
        
        $this->_response($res);
    }

    /*
        更新店铺公告
    */
    public function setShopTopic()
    {
        $store_id = $_POST['store_id'];

        $topic = $_POST['topic'];

        $BdApiModel = new BdApiModel();

        $setShopTopic = $BdApiModel->setShopTopic($store_id, $topic);
        
        if($setShopTopic == false){
            $res = array(
                "errNo" => "0003"
            );
            $this->_response($res);
        }

        if(isset($setShopTopic['errNo'])){
            $this->_response($setShopTopic);
        }

        $res = array(
            "errNo" => "0",
            "data" => $setShopTopic
        );
        
        $this->_response($res);
    }

    /*
        开通自定义分类
    */
    public function openCategory()
    {
        $store_id = $_POST['store_id'];

        $BdApiModel = new  BdApiModel();

        $openCategory = $BdApiModel->openCategory($store_id);

        if($openCategory == false){
            $res = array(
                "errNo" => "0003"
            );
            $this->_response($res);
        }

        if(isset($openCategory['errNo'])){
            $this->_response($openCategory);
        }

        $res = array(
            "errNo" => "0",
            "data" => $openCategory
        );
        
        $this->_response($res);
    }

    /*
        关闭自定义分类
    */
    public function closeCategory()
    {
        $store_id = $_POST['store_id'];

        $BdApiModel = new  BdApiModel();

        $closeCategory = $BdApiModel->closeCategory($store_id);

        if($closeCategory == false){
            $res = array(
                "errNo" => "0003"
            );
            $this->_response($res);
        }

        if(isset($closeCategory['errNo'])){
            $this->_response($closeCategory);
        }

        $res = array(
            "errNo" => "0",
            "data" => $closeCategory
        );
        
        $this->_response($res);
    }

    /*
        初始化自定义分类
    */
    public function initCategoryInfo()
    {
        $store_id = $_POST['store_id'];

        $BdApiModel = new  BdApiModel();

        $initCategoryInfo = $BdApiModel->initCategoryInfo($store_id);

        if($initCategoryInfo == false){
            $res = array(
                "errNo" => "0003"
            );
            $this->_response($res);
        }

        if(isset($initCategoryInfo['errNo'])){
            $this->_response($initCategoryInfo);
        }

        $res = array(
            "errNo" => "0",
            "data" => $initCategoryInfo
        );
        
        $this->_response($res);
    }

    /*
        添加自定义分类
    */
    public function addCategoryInfo()
    {
        $store_id = $_POST['store_id'];
        $category_id = $_POST['category_id'];

        $other_category_name = $_POST['other_category_name'];
        $other_category_rank = $_POST['other_category_rank'];

        $BdApiModel = new  BdApiModel();

        $addCategoryInfo = $BdApiModel->addCategoryInfo($store_id, $category_id, $other_category_name, $other_category_rank);

        if($addCategoryInfo == false){
            $res = array(
                "errNo" => "0003"
            );
            $this->_response($res);
        }

        if(isset($addCategoryInfo['errNo'])){
            $this->_response($addCategoryInfo);
        }

        $res = array(
            "errNo" => "0",
            "data" => $addCategoryInfo
        );
        
        $this->_response($res);
    }

    /*
        更新自定义分类
    */
    public function updateCategoryInfo()
    {
        $store_id = $_POST['store_id'];
        $other_category_id = $_POST['other_category_id'];
        $other_category_name = $_POST['other_category_name'];
        $other_category_rank = $_POST['other_category_rank'];

        $BdApiModel = new  BdApiModel();

        $updateCategoryInfo = $BdApiModel->updateCategoryInfo($store_id, $other_category_id, $other_category_name, $other_category_rank);

        if($updateCategoryInfo == false){
            $res = array(
                "errNo" => "0003"
            );
            $this->_response($res);
        }

        if(isset($updateCategoryInfo['errNo'])){
            $this->_response($updateCategoryInfo);
        }

        $res = array(
            "errNo" => "0",
            "data" => $updateCategoryInfo
        );
        
        $this->_response($res);
    }

    /*
        获取第三方分类信息
    */
    public function getOtherCategoryByBd()
    {
        $store_id = $_POST['store_id'];

        $BdApiModel = new  BdApiModel();

        $getOtherCategoryByBd = $BdApiModel->getOtherCategoryByBd($store_id);

        if($getOtherCategoryByBd == false){
            $res = array(
                "errNo" => "0003"
            );
            $this->_response($res);
        }

        if(isset($getOtherCategoryByBd['errNo'])){
            $this->_response($getOtherCategoryByBd);
        }

        $res = array(
            "errNo" => "0",
            "data" => $getOtherCategoryByBd
        );
        
        $this->_response($res);
    }

    /*
        删除第三方分类
    */
    public function delCategoryInfo()
    {
        $store_id = $_POST['store_id'];
        $other_category_id = $_POST['other_category_id'];

        $BdApiModel = new BdApiModel();

        $delOtherCategory = $BdApiModel->delCategoryInfo($store_id, $other_category_id);

        if($delOtherCategory == false){
            $res = array(
                "errNo" => "0003"
            );
            $this->_response($res);
        }

        if(isset($delOtherCategory['errNo'])){
            $this->_response($delOtherCategory);
        }

        $res = array(
            "errNo" => "0",
            "data" => $delOtherCategory
        );
        
        $this->_response($res);
    }

    /*
        添加药品信息
    */
    public function addProduct()
    {
        $store_id = $_POST['store_id'];
        $product_id = $_POST['product_id']; 
        
        $other_category_id = $_POST['other_category_id'];

        $BdApiModel = new BdApiModel();

        $addProduct = $BdApiModel->addProduct($store_id, $product_id, $other_category_id);

        if($addProduct == false){
            $res = array(
                "errNo" => "0003"
            );
            $this->_response($res);
        }

        if(isset($addProduct['errNo'])){
            $this->_response($addProduct);
        }

        $res = array(
            "errNo" => "0",
            "data" => $addProduct
        );
        
        $this->_response($res);
    }


    /*
        上线商品
    */
    public function onlineProduct()
    {
        $store_id = $_POST['store_id'];
        $product_id = $_POST['product_id'];

        $BdApiModel = new BdApiModel();

        $resp = $BdApiModel->onlineProduct($store_id, $product_id);

        if($resp == false){
            $res = array(
                "errNo" => "0003"
            );
            $this->_response($res);
        }

        if(isset($resp['errNo'])){
            $this->_response($resp);
        }

        $res = array(
            "errNo" => "0",
            "data" => $resp
        );
        
        $this->_response($res);
    }

    /*
        下线商品
    */
    public function offlineProduct()
    {
        $store_id = $_POST['store_id'];
        $product_id = $_POST['product_id'];

        $BdApiModel = new BdApiModel();

        $resp = $BdApiModel->offlineProduct($store_id, $product_id);

        if($resp == false){
            $res = array(
                "errNo" => "0003"
            );
            $this->_response($res);
        }

        if(isset($resp['errNo'])){
            $this->_response($resp);
        }

        $res = array(
            "errNo" => "0",
            "data" => $resp
        );
        
        $this->_response($res);
    }

    /*
        同步商品库存信息
    */
    public function syncStock()
    {
        $store_id = $_POST['store_id'];

        $BdApiModel = new BdApiModel();

        $resp = $BdApiModel->syncStock($store_id);

        if($resp == false){
            $res = array(
                "errNo" => "0003"
            );
            $this->_response($res);
        }

        if(isset($resp['errNo'])){
            $this->_response($resp);
        }

        $res = array(
            "errNo" => "0",
            "data" => $resp
        );
        
        $this->_response($res);
    }

    /*
        同步商品价格信息
    */
    public function syncPrice()
    {
        $store_id = $_POST['store_id'];

        $BdApiModel = new BdApiModel();

        $resp = $BdApiModel->syncPrice($store_id);

        if($resp == false){
            $res = array(
                "errNo" => "0003"
            );
            $this->_response($res);
        }

        if(isset($resp['errNo'])){
            $this->_response($resp);
        }

        $res = array(
            "errNo" => "0",
            "data" => $resp
        );
        
        $this->_response($res);
    }

    /*
        获取远端商品到本地
    */
    public function pullProduct()
    {
        $store_id = $_POST['store_id'];

        $BdApiModel = new BdApiModel();

        $resp = $BdApiModel->pullProduct($store_id);

        if($resp == false){
            $res = array(
                "errNo" => "0003"
            );
            $this->_response($res);
        }

        if(isset($resp['errNo'])){
            $this->_response($resp);
        }

        $res = array(
            "errNo" => "0",
            "data" => $resp
        );
        
        $this->_response($res);
    }

    /*
        获取远端分类到本地
    */
    public function pullCategory()
    {
        $store_id  = $_POST['store_id'];

        $BdApiModel = new BdApiModel();
        $resp = $BdApiModel->pullCategory($store_id);

        if($resp == false){
            $res = array(
                "errNo" => "0003"
            );
            $this->_response($res);
        }

        if(isset($resp['errNo'])){
            $this->_response($resp);
        }

        $res = array(
            "errNo" => "0",
            "data" => $resp
        );
        
        $this->_response($res);
    }
}
?>